<template>
  <div class="sidebar">
    <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
             text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
      <template v-for="item in items">
        <template v-if="item.subs">
          <el-submenu :index="item.index" :key="item.index">
            <template #title>
              <i :class="item.icon"></i>
              <span>{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs">
              <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                <template #title>{{ subItem.title }}</template>
                <el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i" :index="threeItem.index">
                  {{ threeItem.title }}
                </el-menu-item>
              </el-submenu>
              <el-menu-item v-else :index="subItem.index" :key="subItem.index">{{ subItem.title }}
              </el-menu-item>
            </template>
          </el-submenu>
        </template>
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <i :class="item.icon"></i>
            <template #title>{{ item.title }}</template>
          </el-menu-item>
        </template>

      </template>
    </el-menu>

  </div>

</template>

<script>
import {computed, watch} from "vue";
import {useStore} from "vuex";
import {useRoute} from "vue-router";
import router from "../router";


export default {
  name: "Sidebar",
  setup() {
    const items = [
      {
        icon: "el-icon-lx-home",
        index: "/index",
        title: "首页",
      },
      {
        icon: "el-icon-lx-news",
        index: 'display',
        title: "展板",
        subs: [
          {
            index: "/screen",
            title: "病人一览",
          },
          {
            index: "/lobby",
            title: "走廊提示",
          }
        ],
      },
      {
        icon: "el-icon-lx-search",
        index: 'query',
        title: "查询",
        subs: [
          // {
          //     index: "/duty",
          //     title: "值班信息",
          // },
          {
            index: "/bed",
            title: "床位一览",
          },
          {
            index: "/callRecord",
            title: "通话记录",
          },
        ],
      },
      {
        icon: "el-icon-lx-record",
        index: 'call',
        title: "通话",
        subs: [
          {
            index: "/patient",
            title: "呼叫病人",
          },
        ]
      },
      {
        icon: "el-icon-lx-notice",
        index: 'broadcast',
        title: "广播",
        subs: [
          {
            index: "/audio",
            title: "语音库",
          },
          {
            index: "/broadcast",
            title: "定时广播",
          },
          {
            index: "/shout",
            title: "即时广播",
          },
        ],
      },
      {
        icon: "el-icon-lx-settings",
        index: "/setting",
        title: "设置",
      },
    ];

    const route = useRoute();

    const onRoutes = computed(() => {
      return route.path;
    });

    const store = useStore();
    const collapse = computed(() => store.state.collapse);

    return {
      items,
      onRoutes,
      collapse,
    };
  },


};
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  height: 100%;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}

.sidebar::-webkit-scrollbar {
  width: 0;
}

.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}

.sidebar > ul {
  height: 100%;
}
</style>
